package com.vecspace.dayu.code.dao;

import java.util.List;
import org.springframework.stereotype.Repository;

import com.vecspace.database.dao.BaseDao;
import com.vecspace.dayu.code.pojo.Project;

/** DAYU-项目定义,操作数据库的dao类
 * @author: wanghua
 * @reviewer:
 */
@Repository("dayu_projectDao")
public class ProjectDao extends BaseDao {
	/** 根据ID查询 DAYU-项目定义
	 * @param id   主键值
	 * @return Project
	 * @throws Exception
	 */
	public Project getProject(Long id) throws Exception {
		Project project = null;
		if (id != null && id != 0) {

			project = this.queryObject(Project.class, id);
			this.evict(project);
		}
		return project;
	}
	
	/**获取目录下的系统
	 * 
	 * @param catalogId
	 * @return
	 * @throws Exception 
	 * @author wanghua
	 */
	public List<Project> getProjects(Long catalogId) throws Exception {
		List<Project> projects = this.queryObjectList("from Project where catalogId=?0 order by ordnum", new Object[] {catalogId});
		return projects;
	}
	
	public List<Project> getAllProjects() throws Exception {
		List<Project> projects = this.queryObjectList("from Project order by ordnum");
		return projects;
	}
	
	/**获取目录下的系统个数
	 * 
	 * @param catalogId
	 * @return
	 * @throws Exception 
	 * @author wanghua
	 */
	public int getProjectsCount(Long catalogId) throws Exception {
		int rcount = this.queryInt("select count(*) from DAYU_CODE_PROJECT where catalog_id=?", new Object[] {catalogId});
		return rcount;
	}

	/** 插入或修改 DAYU-项目定义 
	 * @param item	要保存的对象
	 * @return void
	 * @throws Exception
	 * @author wanghua
	 */
	public void saveProject(Project item) throws Exception {
		this.saveOrUpdateObject(item);
		this.evict(item);
	}

	/** 根据ID删除 DAYU-项目定义 
	 * @param id	主键值
	 * @return void
	 * @throws Exception
	 * @author wanghua
	 */
	public void deleteProject(Long id) throws Exception {
		if (id != null && id != 0) {
			this.deleteObject(Project.class, id);
		}
	}
}
